#ifndef __SYSTEM_TIMER_H__
#define __SYSTEM_TIMER_H__

#include "serial.h"

typedef struct
{
    unsigned long long ms_intpart;
    double ms_fractpart;
}s_timeval;

typedef void (*timer_callback)(void);

void SystemTimerInit(void);

void SystemTimerStop(void);

void SystemTimer_Handler(void);

int SystemTimer_Setup_Callback(timer_callback cb);

s_timeval* get_timer_time(s_timeval *time);

void delay_us(int us);

void delay_ms(int ms);

int time_is_expired(s_timeval *start, s_timeval *now, double period_ms);

double get_diff_time(s_timeval *start, s_timeval *now);

#define DISPLAT_TIME(enable, promt, time) \
    do{\
    if((enable)){serial_writeline("%s:now time is %lld.%d ms", promt, (time)->ms_intpart, (int)((time)->ms_fractpart*1000));}\
    }while(0)

#endif
